<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        let obj = {
            name: "张三",
            age: 18,
            gender: "男"
        }
        obj[Symbol.iterator] = function () {
            let val = Object.values(obj);
            let idx = -1;//记录索引
            return {
                next: function () {
                    idx++
                    if (idx < val.length) {
                        return { done: false, value: val[idx] }
                    } else {
                        return { done: true, value: val[idx] }
                    }
                }
            }
        }
        for (let item of obj) {
            console.log(item);
        }
    </script>
</body>

</html>